/**
 * 
 */
package org.karthik.ecomm.main;

import org.hibernate.Session;
import org.karthik.ecomm.dto.Address;
import org.karthik.ecomm.dto.Student;
import org.karthik.ecomm.util.HibernateUtil;

/**
 * @author Uday Shankar
 * 
 */
public class StudentMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		HibernateUtil util = new HibernateUtil();
		// Instantiate a new student object which will be persisted
		Student student01 = new Student();
		Address address = new Address();
		Address officeAddress = new Address();

		// Set the student attributes
		student01.setStudentName("Vaibhav");
		student01.setEmailID("vaibhav@gmail.com");
		
		address.setStreet("StreetName");
		address.setCity("Hyderabad");
		address.setState("Andhra Pradesh");
		address.setPincode(500049);
		
		officeAddress.setCity("Chennai");
		officeAddress.setState("Tamil Nadu");
		officeAddress.setPincode(600032);
		
		student01.setAddress(address);
		student01.setOfficeAddress(officeAddress);
		

		// Get a session object from the SessionFactory
		Session session = util.getSession();

		// Persist the student object
		session.beginTransaction();
		session.save(student01);
		session.getTransaction().commit();

		// Closing the session here
		session.close();

	}

}
